<?php
class PrescriptionItem extends ORDataObject{
	var $prescription_item_id 	= 	'';
	var $prescription_id 		= 	'';
	var $medicine_id			= 	'';
	var $usage_title			= 	'';
	var $usage_num 				= 	'';
	var $dosage 				= 	'';
	var $dosage_title                =   '';
	var $time 					= 	'';
	var $quantity_num 			= 	'';
	var $quantity_title 		= 	'';
	var $note 					= 	'';
	var $price					=	'';

	var $_table = 'prescription_item';
	var $_key = 'prescription_item_id';
	var $_internalName = 'PrescriptionItem';
	
	function PrescriptionItem(){
		parent::ORDataObject();		
	}
	
	function delete($prescriptionId) {
		$sql = "DELETE FROM prescription_item WHERE prescription_id = $prescriptionId";
		$this->_execute($sql);
	}
	
	function addNewPrescriptionItem($prescriptionItem){		
		$data = array (
				'prescription_id'		=> 	$prescriptionItem['prescription_id'],
				'medicine_id'			=> 	$prescriptionItem['medicine_id'],
				'usage_title' 			=> 	$prescriptionItem['usage_title'],
				'usage_num'				=> 	$prescriptionItem['usage_num'],
				'dosage'				=> 	$prescriptionItem['dosage'],
		        'dosage_title'          =>  $prescriptionItem['dosage_title'],
				'time'					=> 	$prescriptionItem['time'],
				'quantity_num'			=> 	$prescriptionItem['quantity_num'],
				'quantity_title'		=> 	$prescriptionItem['quantity_title'],
				'note'					=> 	$prescriptionItem['note'],
				'price'					=>	0		
			);		
		$this->populateArray($data);		
		$this->persist();			
		return $this->prescription_item_id;
	}
		
	function getPrescriptionItems($prescriptionId){
				
		$sql = "SELECT prescription_item_id , prescription_id,  medicine_id, proprietary_name medicine_name,
		      usage_title , usage_num, dosage ,dosage_title ,time, quantity_num , quantity_title, note
			 FROM prescription_item pi 
			 	LEFT JOIN drug_material pd ON (pi.medicine_id=pd.drug_material_id)
			 WHERE (prescription_id = $prescriptionId)
			 ORDER BY prescription_item_id";	
		$result = $this->_db->GetAll($sql);		
		return $result;
	}
	
	public function getPrice(){
		return $this->price;
	}
	
	public function setPrice($value){
		$this->price	=	$value;
	}
}
?>